package com.nerve.android.cloudoffice.domain.db;

import android.content.Context;
import android.database.Cursor;

import com.nerve.android.cloudoffice.domain.Message;

public class MessageDao extends Entity<Message>{

	public MessageDao(Context c) {
		super(c);
	}

	@Override
	public String getDBName() {
		return "MESSAGE_";
	}

	@Override
	public String getCreateSQL() {
		StringBuilder sb = new StringBuilder();
		sb.append("create table "+getDBName()+
				" (_id integer primary key autoincrement," +
				"fromUser text," +
				"fromId integer," +
				"toUser text," +
				"toId integer," +
				"message text," +
				"hasRead integer," +
				"groupId integer," +
				"addDate integer);");
		return sb.toString();
	}

	@Override
	public String[] getColumns() {
		return new String[]{
				"_id",
				"fromUser",
				"fromId",
				"toUser",
				"toId",
				"message",
				"hasRead",
				"groupId",
				"addDate"
				};
	}

	@Override
	public Message bind(Cursor c) {
		Message m = new Message();
		
		m.setId(c.getInt(0));
		m.setFromUser(c.getString(1));
		m.setFromId(c.getInt(2));
		m.setToUser(c.getString(3));
		m.setToId(c.getInt(4));
		m.setMessage(c.getString(5));
		m.setRead(c.getInt(6) == 1);
		m.setGroupId(c.getInt(7));
		m.buildDate(c.getLong(8));
		
		return m;
	}

}
